package com.redpack.redpost.struts.action;

//import java.text.SimpleDateFormat;
//import java.util.Date;
//import java.util.Locale;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.redpack.redpost.struts.form.contactoForm;
import com.redpack.redpost.util.dao.UtilDAO;
import com.redpack.redpost.util.to.generalUtil;
import com.redpack.redpost.util.to.validaciones;

public class addContacto extends Action {
	
	public ActionForward execute(
			ActionMapping mapping, 
			ActionForm form, 
			HttpServletRequest request, 
			HttpServletResponse response) throws Exception {
		
		int Resultado = 1 ;
		HttpSession session = request.getSession( ) ;
		contactoForm f = ( contactoForm ) form;
		
//		SimpleDateFormat formato2 = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()) ;
//		Date fechaDate = new Date();
		String fecha = generalUtil.obtenerFechaActual( ) ; //formato2.format(fechaDate);
		
		
			String salida = "success",
					idioma = "";
			
			if ( session.getAttribute("idioma") != null ){
				idioma = session.getAttribute("idioma").toString();

			}
			
			salida = validaciones.idioma(salida, idioma) ;
			
			
		try {
			
			boolean nuevo = UtilDAO.agregaRegistroContactanos(f.getNombre( ), f.getEmail( ), f.getAsunto( ), f.getSugerencia( ), fecha) ;
			
			if( !nuevo )
				Resultado = 2 ;
			
		}catch( Exception e ) {
			
			e.printStackTrace( ) ;
			
			request.setAttribute("R", ""+ 2 ) ;			
			return mapping.findForward(salida);
			
		}				
		
		
		request.setAttribute("R", ""+ Resultado ) ;
		
		return mapping.findForward(salida);
		
	}

}
